package com.example.fragment_work;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.ViewHolder;

import java.util.List;

public class RightAdapter extends BaseAdapter {

    private Context mContext;
    private List<FoobBeen> list;

    public RightAdapter(Context mContext, List<FoobBeen> list) {
        this.mContext = mContext;
        this.list = list;
    }
    @Override
    public int getCount() {
        return list.size();
    }
    @Override
    public Object getItem(int position) {
        return list.get(position);
    }
    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
          convertView=View.inflate(mContext,R.layout.list_item,null);
          holder=new ViewHolder() ;
          holder.tv_name=convertView.findViewById(R.id.tv_name);
          holder.tv_sales=convertView.findViewById(R.id.tv_sales);
          holder.tv_price=convertView.findViewById(R.id.tv_price);
          holder.iv_img=convertView.findViewById(R.id.iv_img);
          convertView.setTag(holder);
        }else {
            holder=(ViewHolder) convertView.getTag();
        }
        FoobBeen bean = list.get(position);
        holder.tv_name.setText(bean.getName());
        holder.tv_sales.setText(bean.getSales());
        holder.tv_price.setText(bean.getPrice());
        holder.iv_img.setImageResource(bean.getImg());
        return convertView;
    }
    class ViewHolder{
        TextView tv_name,tv_sales,tv_price;
        ImageView iv_img;
    }
}
